Skip to content

Replace create() classmethods with __init__ constructors#310

Merged
NodeJSmith merged 4 commits intomainfrom
eliminate-create-classmethod
Feb 24, 2026
Merged

Replace create() classmethods with __init__ constructors#310
NodeJSmith merged 4 commits intomainfrom
eliminate-create-classmethod

Conversation

@NodeJSmith
Copy link
Owner

Summary

  • Replace @classmethod create() factory pattern with standard __init__() constructors across all 17 Resource subclasses, eliminating the inspect.signature indirection in add_child() and the base Resource.create() method
  • Simplify add_child() from introspecting the child's create() signature to conditionally pass args, to a direct child_class(hassette=self.hassette, parent=self, **kwargs) call
  • Update the StateManager type stub and all test call sites to match the new construction pattern

25 files changed, -82 lines net. All 1053 tests pass, pyright clean.

The Resource class hierarchy used @classmethod create() factories that
instantiated the class, set attributes on the instance, and returned it.
This indirection required inspect.signature introspection in add_child()
to conditionally pass arguments — fragile and hard to follow.

Replace all create() classmethods with standard __init__ constructors
that call super().__init__() and set attributes directly. Simplify
add_child() to a direct constructor call. Remove the inspect import
and the base Resource.create() method entirely.

25 files, -81 lines net. All 1053 tests pass, pyright clean.
Copilot AI review requested due to automatic review settings February 24, 2026 19:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the @classmethod create() factory pattern from Hassette Resource subclasses and shifts construction to standard __init__ constructors, simplifying child creation and aligning tests/types with the new instantiation style.

Changes:

  • Removed Resource.create() and simplified Resource.add_child() to directly instantiate child resources via constructors.
  • Converted multiple Resource/Service subclasses from create() factories to __init__() initialization.
  • Updated state manager typing stub and test call sites to use direct construction instead of .create().

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/hassette/resources/base.py Removes Resource.create() and changes add_child() to call constructors directly.
src/hassette/task_bucket/task_bucket.py Replaces TaskBucket.create() with __init__() initialization and readiness marking.
src/hassette/state_manager/state_manager.py Adds StateManager.__init__() and removes the previous create() factory.
src/hassette/state_manager/state_manager.pyi Updates stub to reflect constructor-based initialization.
src/hassette/scheduler/scheduler.py Converts Scheduler.create() factory into __init__().
src/hassette/core/websocket_service.py Converts WebsocketService.create() factory into __init__().
src/hassette/core/web_api_service.py Converts WebApiService.create() factory into __init__().
src/hassette/core/state_proxy.py Converts StateProxy.create() factory into __init__() wiring of children/state.
src/hassette/core/service_watcher.py Converts ServiceWatcher.create() factory into __init__().
src/hassette/core/scheduler_service.py Converts SchedulerService.create() and _ScheduledJobQueue.create() into __init__().
src/hassette/core/data_sync_service.py Converts DataSyncService.create() factory into __init__().
src/hassette/core/bus_service.py Converts BusService.create() factory into __init__() (including stream kw-only).
src/hassette/core/app_handler.py Converts AppHandler.create() factory into __init__()-based wiring.
src/hassette/core/app_factory.py Updates app instantiation from app_class.create(...) to app_class(...).
src/hassette/core/api_resource.py Converts ApiResource.create() factory into __init__().
src/hassette/core/core.py Updates Hassette construction to use TaskBucket(...) instead of TaskBucket.create(...).
src/hassette/bus/bus.py Converts Bus.create() factory into __init__() while preserving behavior.
src/hassette/api/api.py Converts Api.create() factory into __init__() and updates sync facade child creation.
src/hassette/api/sync.py Replaces ApiSyncFacade.create() with __init__() (note: file is marked auto-generated).
src/hassette/app/app.py Converts App.create() factory into __init__() wiring of child resources.
src/hassette/test_utils/harness.py Updates harness to instantiate TaskBucket(...) directly.
tests/unit/test_app_factory.py Updates mocks/assertions for constructor calls rather than .create().
tests/integration/test_websocket_service.py Updates fixture to construct WebsocketService(...) directly.
tests/integration/test_states.py Updates StateManager construction from .create() to direct instantiation.
tests/integration/test_state_proxy.py Updates StateProxy construction from .create() to direct instantiation.
tests/integration/test_service_watcher.py Updates ServiceWatcher construction from .create() to direct instantiation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings February 24, 2026 20:06
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@NodeJSmith NodeJSmith merged commit 9d0147c into main Feb 24, 2026
10 checks passed
@NodeJSmith NodeJSmith deleted the eliminate-create-classmethod branch February 24, 2026 20:40
@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 98.31933% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.99%. Comparing base (e4ebf95) to head (31404c6).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/hassette/core/database_service.py 87.50% 1 Missing ⚠️
src/hassette/core/websocket_service.py 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #310      +/-   ##
==========================================
- Coverage   80.07%   79.99%   -0.09%     
==========================================
  Files         134      134              
  Lines        9586     9531      -55     
  Branches      948      943       -5     
==========================================
- Hits         7676     7624      -52     
  Misses       1538     1538              
+ Partials      372      369       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants